<template>
	<view>
		<view v-if="isLogin">
			<view class="head-container">
				<image :src="avatar" mode="aspectFill" class="img-avatar"></image>
				<view class="user-info-container">
					<view class="nick-type-container">
						<text class="txt-nick">{{nickName+"【"+uTypes[type]+"】"}}</text>
					</view>
				</view>
			</view>
			<text class="iconfont icon-ziyuanxhdpi  txt-logout" @click="clickLogout"></text><!-- 注销 -->
		</view>
		<view class="head">
			<view v-if="type==0" class="content">
				<view class="content-admin" @click.stop="clickProfile">
					<image src="../../static/icons/4.jpg" mode="widthFix" class="logo1"></image>
					
					<text class="text-con">个人中心</text>
				</view>

				<view class="content-ck" @click.stop="clickUser">
					<image src="../../static/icons/5.jpg" mode="widthFix" class="logo2"></image>
					<view class="text-con">用户管理</view>
				</view>

				<view class="content-ck" @click.stop="clickQXGL">
					<image src="../../static/icons/6.jpg" mode="widthFix" class="logo2"></image>

					<view class="text-con">权限管理</view>
				</view>
			</view>
		</view>

		<view v-if="type==1" class="content">
			<view class="content-admin" @click.stop="clickProfile">
				<image src="../../static/icons/4.jpg" mode="widthFix" class="logo1"></image>
				<view class="text-con">个人中心</view>
			</view>
			<view class="content-ck" @click.stop="clickApply">
				<image src="../../static/icons/2.jpg" mode="widthFix" class="logo2"></image>
				<view class="text-con">学生管理</view>
			</view>
			<view class="content-ck" @click.stop="clickAddCK">
				<image src="../../static/icons/1.jpg" mode="widthFix" class="logo1"></image>
				<view class="text-con">添加课程</view>
			</view>
			<view class="content-tck" @click.stop="clickTC">
				<image src="../../static/icons/3.jpg" mode="widthFix" class="logo3"></image>
				<view class="text-con" >课程管理</view>
			</view>
		</view>

		<view v-if="type==2" class="content">
			<view class="content-admin" @click.stop="clickProfile">
				<image src="../../static/icons/4.jpg" mode="widthFix" class="logo1"></image>
				
				<view class="text-con">个人中心</view>
			</view>
			<view class="content-ck" @click.stop="clickSC">
				<image src="../../static/icons/3.jpg" mode="widthFix" class="logo2"></image>
				
				<view class="text-con">课程列表</view>
			</view>
		</view>
		<login-dialog ref="login" @after="afterLogin"></login-dialog>
	</view>
</template>
<script>
	const app = getApp()
	let newName = ""
	let updateId = ""
	let page = 0
	let ids = []
	export default {
		data() {
			return {
				isLogin: app.globalData.token.length > 0,
				avatar: this.$params.host + app.globalData.avatar,
				name: '',
				email: '',
				nickName: '',
				type: app.globalData.type,
				uTypes: ["管理员", "教师", "学生"],
			}
		},
		mounted() {
			if (!this.isLogin) {
				this.$refs.login.show()
			}
		},
		onShow() {
			if (!this.isLogin) {
				return
			}

		},
		onLoad() {
			this.$noti.add(this.$params.noti_login_status, this, this.afterLogin)
		},
		onUnload() {
			this.$noti.remove(this.$params.noti_login_status, this)
		},

		methods: {
			afterLogin(logout) {
				if (logout) {
					this.$refs.login.show()
					return
				}

				this.isLogin = app.globalData.token.length > 0

				this.avatar = this.$params.host + app.globalData.avatar
				this.type = app.globalData.type
				this.name = app.globalData.userName
				this.email = app.globalData.email
				this.nickName = app.globalData.nickName
				// this.$refs.login.hide()


			},
			clickLogout() {
				this.isLogin = false
				app.globalData.avatar = '/static/default_user.png'
				app.globalData.uid = ''
				app.globalData.userName = ''
				app.globalData.nickName = ''
				app.globalData.type = -1
				app.globalData.email = ''
				app.globalData.token = ''
				app.globalData.apply = ''
				app.globalData.phone = ''
				this.$noti.post(this.$params.noti_login_status, true)
			},
			clickUser() {
				uni.navigateTo({
					url: '../admin/admin',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			clickAddCK() {
				uni.navigateTo({
					url: '../teacher/Acourse/Acourse',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},

			clickTC() {
				uni.navigateTo({
					url: '../teacher/Tcourse/Tcourse',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			clickQXGL(){
				uni.navigateTo({
					url: '../admingx/admingx',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			clickSC() {
				uni.navigateTo({
					url: '../student/Scourse',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
		}
	}
</script>

<style>
	@import url("index.css");
</style>
